package com.ruoyi.food.mapper;



import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.food.object.TAttach;

import springfox.documentation.swagger.web.SwaggerApiListingReader;


@Mapper
public interface TAttachMapper extends BaseMapper<TAttach>{
	
	@Insert({"<script>",
        "insert into t_attach(ATT_NAME,ATT_FK_NAME,ATT_FK_ID,ATT_DOMAIN,ATT_WEB_URL,ATT_SCALE_URL,ATT_URL,ATT_TIME,ATT_USER,ATT_COUNT,ATT_VALID) values",
        "<foreach collection='tAttachs' item='item' index='index' separator=','>",
        "(#{item.attName}, #{item.attFkName}, #{item.attFkId}, #{item.attDomain}, #{item.attWebUrl}, #{item.attScaleUrl}, #{item.attUrl}, #{item.attTime}, #{item.attUser}, #{item.attCount}, 1)",
        "</foreach>",
        "</script>"})
	public void insertBatchTAttach(@Param(value="tAttachs") List<TAttach> tAttachs);
	
	@Select("SELECT *from t_attach where ATT_FK_ID=#{attFkId} and ATT_FK_NAME like concat('%', #{attFkName}, '%') and ATT_VALID=1")
	public List<TAttach> selectTAttachByFK(@Param("attFkId")long attFkId,@Param("attFkName")String attFkName);
	
	/**
	 * 逻辑删除(通过附件id集合)
	 * @param attIds
	 */
	@Update({"<script>",
        "update t_attach set ATT_VALID=0 where ATT_ID=",
        "<foreach collection='attIds' item='attId' index='index' separator=','>",
        "#{attId}",
        "</foreach>",
        "</script>"})
	public void deleteTAttachById(@Param("attIds")List<Long> attIds);
	
	/**
	 * 逻辑删除（通过关联表id）
	 * @param attFkId
	 * @param attFkName
	 */
	@Update("update t_attach set ATT_VALID=0 where ATT_FK_ID=#{attFkId} and ATT_FK_NAME like concat('%', #{attFkName}, '%')")
	public void deleteByattFkId(@Param("attFkId")long attFkId,@Param("attFkName")String attFkName);
	
	/**
	 * 通过id修改ATT_FK_NAME
	 * @param attId
	 * @param attFkName
	 */
	@Update("update t_attach set ATT_FK_NAME=#{attFkName} where ATT_ID=#{attId}")
	public void updateFkNameByAttId(@Param("attId")long attId,@Param("attFkName")String attFkName);

}
